#include <bits/stdc++.h>
using namespace std;
const int N=6e6+6,M=N*2,inf=1e8;
int n,m,k;
#define num(x,y,z) ((x>n||y>m)?(n*m*2+1):(((x)-1)*(m)+(y)+(z)*(n*m)))
int sx,sy,tx,ty,s,t;
bool a[N];
int dis[M];
struct point
{
	int x,y,z;
};
point q[M],p[M];
int cntq,cntp;
const int det[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
const int dir[4][2]={{1,1},{1,-1},{-1,-1},{-1,1}};

struct dsu
{
	int fa[M];
	int find(int x)
	{
		if (x>n*m*2||x==fa[x]) return x;
		return fa[x]=find(fa[x]);
	}
	void merge(int x,int y)
	{
		x=find(x),y=find(y);
		fa[x]=y;
	}
}A,B;
void ADD(int x,int y)
{
	A.fa[num(x,y,1)]=num(x+1,y,1);
	B.fa[num(x,y,1)]=num(x,y+1,1);
}
inline int askX(int u)
{
	if (u>n*m) u-=n*m;
	u--;
	return u/m+1;
}
inline int askY(int u)
{
	if (u>n*m) u-=n*m;
	u--;
	return u%m+1;
}

int main()
{
	freopen("stamp.in","r",stdin);
	freopen("stamp.out","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	memset(dis,20,sizeof(dis));
	cin >> n >> m >> k;
	cin >> sx >> sy >> tx >> ty;
	s=num(sx,sy,0),t=num(tx,ty,1);
	for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) 
	{
		char x;
		cin >> x;
		if (x=='#') a[num(i,j,0)]=1;
		A.fa[num(i,j,1)]=num(i,j,1);
		B.fa[num(i,j,1)]=num(i,j,1);
	}
	q[++cntq]={sx,sy,0};
	dis[s]=0;
	while (1)
	{
		int l=1;
		while (l<=cntq)
		{
			point u=q[l++];
			// cout << u.x << " " << u.y << " " << u.z << endl;
			// cout << dis[num(u.x,u.y,u.z)] << endl;
			if (u.z==1)
			{
				for (int i=0;i<4;i++)
				{
					int x=u.x+det[i][0],y=u.y+det[i][1];
					int z=u.z^1;
					if (x<1||x>n||y<1||y>m) continue;
					if (dis[num(x,y,z)]>=inf) 
					{
						dis[num(x,y,z)]=dis[num(u.x,u.y,u.z)];
						q[++cntq]={x,y,z};
			
					}
				}	
			}
			if (u.z==0&&a[num(u.x,u.y,u.z)]==0)
			{
				if (dis[num(u.x,u.y,1)]>=inf) 
				{
					dis[num(u.x,u.y,1)]=dis[num(u.x,u.y,u.z)];
					q[++cntq]={u.x,u.y,1};
					ADD(u.x,u.y);
				}
			}
		}
		cntp=0;
		for (int i=1;i<=cntq;i++)
		{
			point u=q[i];
			if (u.z==1) continue;
			for (int i=0;i<4;i++)
			{
				int x1=u.x+dir[i][0]*(k-1),y1=u.y+dir[i][1]*(k-1);
				int x2=u.x+dir[(i+1)%4][0]*(k-1),y2=u.y+dir[(i+1)%4][1]*(k-1);
				if (x1>x2) swap(x1,x2);
				if (y1>y2) swap(y1,y2);
				x1=max(x1,1),x2=min(x2,n);
				y1=max(y1,1),y2=min(y2,m);
				if (x1>x2||y1>y2) continue;
				if (x1==x2)
				{
					int x=x1;
					for (int y=num(x,y1,1);y<=num(x,y2,1);y=B.find(y))
					{
						if (dis[y]>=inf) 
						{
							dis[y]=dis[num(u.x,u.y,u.z)]+1;
							p[++cntp]={x,askY(y),1};
						}
						ADD(askX(y),askY(y));
						//cout << y << " " << B.find(y) << " " << askX(y) << " " << askY(y)<< endl;
					}
				}
				else
				{
					int y=y1;
					for (int x=num(x1,y,1);x<=num(x2,y,1);x=A.find(x))
					{
						if (dis[x]>=inf) 
						{
							dis[x]=dis[num(u.x,u.y,u.z)]+1;
							p[++cntp]={askX(x),y,1};
						}
						ADD(askX(x),askY(x));
						//cout << x << " "<<x2<<" "<<y<< " " << num(x2,y,1)<< " " << A.find(x) << " " << askX(x) << " " << askY(x)<< endl;
					}
				}
			}
		}
		cntq=cntp;
		for (int i=1;i<=cntq;i++) q[i]=p[i];
		if (cntq==0) break;
	}
	int ans=dis[t];
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=m;j++)
		{
			if (abs(i-tx)<k&&abs(j-ty)<k)
			{
				ans=min(ans,dis[num(i,j,0)]+1);
				ans=min(ans,dis[num(i,j,1)]+1);
			}
		}
	}
	cout << ans;
	return 0;
}
